﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DCHealthCheck.MvcWeb.Classes.ViewModels.HomeViewModel>" %>

<%@ Import Namespace="DCHealthCheck.MvcWeb.Classes" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    <%:Global.ApplicationName%>::<%:Model.ControllerName%>
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <div id="infobox">
        <%Html.RenderPartial("DateFilterControl"); %>
    </div>
    <div id="contents">
        <div id="leftcontainer">
            <%Html.RenderPartial("TableHeader", this.Model); %>
            <%Html.RenderPartial("HealthCheckSummariesTable");%>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptsSection" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
        });
        function deleteResults(date) {
            $.unblockUI();
            $("#dialog-confirm-okCancel-text").text('Delete Health Check Results for date: ' + date + ' from database?');
            $("#dialog-confirm-okCancel").dialog({
                title: "Confirm Action",
                height: 250,
                width: 500,
                buttons: {
                    "OK": function () {
                        $.blockUI({ message: '<br /><img src="../images/loadingAnimation.gif" /><h2> Please wait...</h2>', fadeIn: 500 });
                        var controller = '/<%:ViewData["routeName"].ToString() %>';
                        $.ajax({
                            type: "POST",
                            url: controller + "/DeleteResults",
                            data: {
                                date: date
                            },
                            async: true,
                            timeout: 300000,
                            complete: function () { $.unblockUI(); },
                            success: function () {
                                var searchFilter = "deleteResults\\(\\'" + date;

                                // fadeTo is non-functional in IE8
                                $("a[onclick*=" + searchFilter + "]").parent().parent()
                                .fadeTo(3000, 0.3, function () {
                                    $(this).hide();
                                });

                                $("a[onclick*=" + searchFilter + "]").parent().parent().children().children()
                                .removeAttr("onclick").removeAttr("href");

                                $("#dialog-confirm-ok-text").text("Health Check Results deleted");
                                $("#dialog-confirm-ok").dialog("option", "title", "Action Successful").dialog("open");
                            },
                            error: function () {
                                $("#dialog-confirm-error").text("Check the server logs for details.");
                                $("#dialog-confirm-error").dialog("option", "title", "Action Unsuccessful").dialog("open");
                            }
                        });
                        $(this).dialog("close");
                    },
                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });
            $("#dialog-confirm-okCancel").dialog("open");

        }

        function showHealthCheckSummary(Id) {

            var controller = "/<%=ViewData["routeName"].ToString() %>";
                spinblock();
                $.ajax({
                    type: "GET",
                    url: controller + "/GetHealthCheckSummary",
                    data: {
                        Id: Id
                    },
                    success: function (html) {
                        var $legendDialog = $('<div style="background-color:#FFFFF5;"></div>')
                            .html(html)
                            .dialog({
                                autoOpen: false,
                                modal: true,
                                title: 'Health Check Summary',
                                height: '360',
                                width: '920'
                            });

                        $legendDialog.dialog('open');
                    } // Success 
                });

                $.unblockUI();
            }
    </script>
</asp:Content>
